﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Markup;
using CommonLibrary.Helper;
using CuteWallpaperDemo.Managers;

namespace CuteWallpaperDemo.Models
{
    public class BitmapImageConverter : MarkupExtension, IValueConverter
    {
        public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is string url))
            {
                return null;
            }
            string title = Path.GetFileNameWithoutExtension(url);
            string cache = DomainHelper.GetCachedFilePath(url);

            switch (parameter)
            {
                case "name":
                    return title;
                case "2":     // 中等压缩
                    return NewWallpaperManager.GetMiddle(cache);
                case "3":     // 低分辨率
                    return NewWallpaperManager.GetPreview(cache);
                case "1":
                default:    // 原图
                    return NewWallpaperManager.GetOrigin(cache);
            }
        }

        public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }
    }
}
